import 'package:environmental_les_app/common/style/colours.dart';
import 'package:environmental_les_app/common/widgets/clear_text.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_clx_base/utils/string_util.dart';

import 'pwd_hint_text.dart';
import 'send_code_widget.dart';

/// 输入框Item
class InputItem extends StatelessWidget {
  final TextEditingController? controller; //控制器
  final String? hintText; //提示文字
  final int type; // 类型 1 手机号 2 密码 3 验证码 4交易密码短信(旧马上来)
  final int? maxLength; //最大输入长度
  final String vCodeType; // 验证码发送类型
  final TextEditingController? phoneController; // 手机号controller
  final FocusNode? focusNode;
  final bool enableEdit; // 是否可编辑
  final List<TextInputFormatter>? inputFormatters;
  final Color? color; //获取验证文字主题色
  final int? verificationType; // 验证码滑块的验证类型

  const InputItem({
    super.key,
    this.controller,
    this.hintText,
    this.type = 1,
    this.maxLength,
    this.vCodeType = "",
    this.phoneController,
    this.focusNode,
    this.enableEdit = true,
    this.inputFormatters,
    this.verificationType = 1,
    this.color,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      constraints: const BoxConstraints(minHeight: 50.0),
      padding: const EdgeInsets.only(left: 30.0),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8.0),
      ),
      child: Row(
        children: [
          type == 2
              ? Expanded(
                  child: PwdHintText(
                    controller: controller,
                    focusNode: focusNode,
                    hintText: hintText,
                    maxLength: maxLength,
                    fontWeight: FontWeight.bold,
                    hintFontWeight: FontWeight.bold,
                    hintColor: Colours.color989FA8,
                    inputColor: Colours.text254,
                  ),
                )
              : Expanded(
                  child: ClearText(
                    controller: controller,
                    focusNode: focusNode,
                    hintText: hintText,
                    keyboardType: TextInputType.phone,
                    maxLines: 1,
                    maxLength: maxLength,
                    fontWeight: FontWeight.bold,
                    hintFontWeight: FontWeight.bold,
                    hintColor: Colours.color989FA8,
                    inputColor: Colours.text254,
                    enabled: enableEdit,
                    paddingEnd: 10.0,
                    inputFormatters: inputFormatters,
                  ),
                ),
          //获取验证码
          Visibility(
            visible: type == 3 || type == 4,
            child: Container(
              alignment: Alignment.center,
              constraints: const BoxConstraints(minWidth: 110.0),
              child: Padding(
                padding: const EdgeInsets.only(right: 0),
                child: SendCodeWidget(
                  vCodeType,
                  () => getControllerString(phoneController),
                  color: color,
                ),
              ),
            ),
          )
        ],
      ),
    );
  }
}
